package ua

import (
	"context"

	"github.com/gopcua/opcua"
)
import "github.com/gopcua/opcua/ua"

type Client struct {
	client        *opcua.Client
	clientContext context.Context
}

func (u *Client) Connect(url string) error {
	client, err := opcua.NewClient(url, opcua.SecurityMode(ua.MessageSecurityModeNone))
	if err != nil {
		return err
	}
	// 连接客户端
	if err := client.Connect(context.Background()); err != nil {
		return err
	}
	u.client = client
	u.clientContext = context.Background()
	return nil
}

func (u *Client) Close() {
	if u.client != nil {
		err := u.client.Close(u.clientContext)
		if err != nil {
			return
		}
	}
}
